package com.shycloud.mido.member.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Xiaoxing Yu
 * @date 2020/10/20 10:12
 **/
@Configuration
public class QuartzConfig {

	@Bean
	public JobDetail uploadTaskDetail() {
		return JobBuilder.newJob(OnlineCourseEverydayJob.class).withIdentity("onlineCourseEverydayJob").storeDurably().build();
	}

	@Bean
	public Trigger uploadTaskTrigger() {
		//设置执行频率
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("00 55 23 * * ?");
		return TriggerBuilder.newTrigger().forJob(uploadTaskDetail())
				.withIdentity("onlineCourseEverydayJob")
				.withSchedule(scheduleBuilder)
				.build();
	}

	@Bean
	public JobDetail uploadTaskDetail2() {
		return JobBuilder.newJob(AssignLimitUpdateJob.class).withIdentity("assignLimitUpdateJob").storeDurably().build();
	}

	@Bean
	public Trigger uploadTaskTrigger2() {
		//设置执行频率
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 1 1,3,5,7,9,11 ?");
		return TriggerBuilder.newTrigger().forJob(uploadTaskDetail2())
				.withIdentity("assignLimitUpdateJob")
				.withSchedule(scheduleBuilder)
				.build();
	}

	@Bean
	public JobDetail pushMessageDetail() {
		return JobBuilder.newJob(PushMessageJob.class).withIdentity("pushMessageJob").storeDurably().build();
	}

	@Bean
	public Trigger pushMessageTrigger() {
		//设置执行频率
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 18 * * ?");
		return TriggerBuilder.newTrigger().forJob(pushMessageDetail())
				.withIdentity("pushMessageJob")
				.withSchedule(scheduleBuilder)
				.build();
	}

	@Bean
	public JobDetail getMemberCount() {
		return JobBuilder.newJob(MemberCountDetailJob.class).withIdentity("memberCountDetailJob").storeDurably().build();
	}

	@Bean
	public Trigger getMemberCountTrigger() {
		//设置执行频率
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 6 * * ?");
		return TriggerBuilder.newTrigger().forJob(getMemberCount())
				.withIdentity("memberCountDetailJob")
				.withSchedule(scheduleBuilder)
				.build();
		//https://blog.csdn.net/qq_35273009/article/details/107458592
	}

}
